/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package until;
import java.io.ByteArrayInputStream;
import java.security.MessageDigest;

/**
 *
 * @author Administrator
 */
public class Md5 {
    public static String MaHoaMd5(String input){
        try {
            MessageDigest md= MessageDigest.getInstance("MD5");
            byte[]processString=input.getBytes();
            processString=md.digest(processString);
            input=toHexadecimal(processString);
            return input;
        } catch (Exception e) {
        }
        return input;
                
    }
    private static String toHexadecimal(byte[]data ){
        String result="";
        ByteArrayInputStream input=new ByteArrayInputStream(data);
        String cadAux;
        boolean flag=false;
        int testcase=input.read();
        while (testcase!=-1) {    
            cadAux=Integer.toHexString(testcase);
            if (cadAux.length()<2) {
                result+="0";
                if (cadAux.length()==0) 
                    flag=true;
            }else{
                    flag=false;
                }
                result+=cadAux;
                testcase=input.read();
            }
            if (flag) 
                result=result.substring(0,result.length()-2+result.charAt(result.length()-1));
                return result;
        }
    }

